document.addEventListener('DOMContentLoaded', function() {
    viewProfile();
});

function viewProfile() {
    fetch('/blog/user/checkMyself')
        .then(response => response.json())
        .then(data => {
            const profileDiv = document.getElementById('profile');
            if (data.code === 1) {
                profileDiv.innerHTML = `
                <p>ID: ${data.data.id}</p>
                <p>用户名: ${data.data.username}</p>
                <p>邮箱: ${data.data.email}</p>
                <p>性别: ${data.data.sex}</p>
            `;
            } else {
                profileDiv.innerHTML = `<p>加载失败：${data.msg}</p>`;
            }
        })
        .catch(error => {
            const profileDiv = document.getElementById('profile');
            profileDiv.innerHTML = `<p>请求失败：${error.message}</p>`;
        });
}
